package thinkinjava4.ch21_concurrency;


class UnresponsiveUI {
    private volatile double d = 1;

    public UnresponsiveUI() throws Exception {
        System.out.println("UnresponsiveUI start");
        while (d > 0) {
            d = d + (Math.PI + Math.E) / d;
        }
        System.in.read();//Never gets here
        System.out.println("UnresponsiveUI end");
    }
}

public class ResponsiveUI extends Thread {
    private static volatile double d = 1;

    public ResponsiveUI() {
        setDaemon(true);
        start();
    }

    @Override
    public void run() {
        System.out.println("ResponsiveUI start");
        while (true) {
            d = d + (Math.PI + Math.E) / d;
        }
    }

    public static void main(String[] args) throws Exception {
//        new UnresponsiveUI();
        new ResponsiveUI();

        System.in.read();
        System.out.println(d);
    }
}
